package com.xls.controllerr;

import com.xls.domain.Orderinfo;
import com.xls.dto.CustomerDTO;
import com.xls.dto.Result;
import com.xls.service.OrderinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/orders")
public class OrderController {
    @Autowired
    OrderinfoService orderService;

    @PostMapping("/add")
    public Result addOrder(@RequestBody Orderinfo order) {
        return Result.ok(orderService.save(order));
    }
    @GetMapping("/{id}")
    public Result getOrderById(@PathVariable("id") Long id) {
        return Result.ok(orderService.getById(id));
    }

    @GetMapping("/list")
    public Result getOrderList() {
        return Result.ok(orderService.list());
    }

    @PostMapping("/getOrders")
    public Result getOrderListByUserId(@RequestBody CustomerDTO customerDTO) {
        return Result.ok(orderService.getOrderByUserId(customerDTO.getUserId()));
    }
}
